var gulp = require('gulp'),
    jade = require('gulp-jade'),
    imagemin = require('gulp-imagemin'),
    uglify = require('gulp-uglify');
 
var watchPath = {
	jade: './js_practice/dom/template/*.jade',
    js: './js_practice/dom/js/*.js',
    h5: './h5_practice/',
};

//dom begin
//jade模板
gulp.task('jade', function() {
  var YOUR_LOCALS = {};
  gulp.src(watchPath.jade)
    .pipe(jade({
      pretty: true
    }))
    .pipe(gulp.dest('./js_practice/dom/build/'))
});

//js
gulp.task('js', function() {
    //js代码校验
   // return gulp.src('javascripts/*.js')
   //     .pipe(jshint())
   //     .pipe(jshint.reporter('default'))
   //     //js代码合并
   //     .pipe(concat('all.js'))
        //给文件添加.min后缀
        gulp.src(watchPath.js)
        //.pipe(rename({ suffix: '.min' }))
        //压缩脚本文件
        .pipe(uglify())
        //输出压缩文件到指定目录
        .pipe(gulp.dest('./js_practice/dom/build/'));
        //提醒任务完成
        //.pipe(notify({ message: 'Scripts task complete' }));
});

//images
gulp.task('images', function(){
	gulp.src('./js_practice/dom/images/*.{gif,jpg,png,ico}')
	.pipe(imagemin())
	.pipe(gulp.dest('./js_practice/dom/build/images'));
});

gulp.task('allReload', ['jade', 'js'],function(){
	//reload();
});

gulp.task('default',['jade','js','images'], function() {
     gulp.watch(
        [watchPath.jade].concat(watchPath.js)
        , ['allReload']);//.on('change', reload);
});
//dom end

//h5
gulp.task('h5', function () {
    gulp.watch(watchPath.h5 + '*.jade', function () {
        gulp.src(watchPath.h5 + '*.jade')
            .pipe(jade({
                pretty: true
            }))
            .pipe(gulp.dest(watchPath.h5 + 'html/'));

        console.log('h5 jade done')
    });
});